{% macro initial_cluster() -%}
{% for host in groups['etcd'] -%}
  {{ hostvars[host]['ansible_hostname'] }}=https://{{ hostvars[host]['etcd_machine_address'] }}:{{ etcd_peer_port }}
  {%- if not loop.last -%},{%- endif -%}
{%- endfor -%}
{% endmacro -%}

#see https://github.com/coreos/etcd/blob/master/Documentation/op-guide/configuration.md
#[Member]
ETCD_NAME={{ ansible_hostname }}
ETCD_DATA_DIR={{ etcd_data_dir }}
ETCD_LISTEN_PEER_URLS={{ etcd_listen_peer_urls }}
ETCD_LISTEN_CLIENT_URLS="{{ etcd_listen_client_urls }}"
#[Clustering]
ETCD_INITIAL_CLUSTER="{{ initial_cluster() }}"
ETCD_INITIAL_CLUSTER_STATE={{ etcd_initial_cluster_state }}
ETCD_INITIAL_CLUSTER_TOKEN={{ etcd_initial_cluster_token }}
ETCD_INITIAL_ADVERTISE_PEER_URLS={{ etcd_initial_advertise_peer_urls }}
ETCD_ADVERTISE_CLIENT_URLS={{ etcd_advertise_client_urls }}
#[Security]
ETCD_CA_FILE={{ etcd_ca_file }}
ETCD_CERT_FILE={{ etcd_cert_file }}
ETCD_KEY_FILE={{ etcd_key_file }}
ETCD_CLIENT_CERT_AUTH={{ etcd_client_cert_auth }}
ETCD_TRUSTED_CA_FILE={{ etcd_ca_file }}
ETCD_PEER_CA_FILE={{ etcd_peer_ca_file }}
ETCD_PEER_TRUSTED_CA_FILE={{ etcd_peer_ca_file }}
ETCD_PEER_CERT_FILE={{ etcd_peer_cert_file }}
ETCD_PEER_KEY_FILE={{ etcd_peer_key_file }}
ETCD_PEER_CLIENT_CERT_AUTH={{ etcd_peer_client_cert_auth }}
